home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac-Source 1994 July
/
Mac-Source_July_1994.iso
/
C and C++
/
Libraries
/
usr (gcc 1.37 libs)
/
mac
/
write.c
< prev
Wrap
C/C++ Source or Header
|
1993-12-14
|
1KB
|
56 lines
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include "crtlocal.h"
ssize_t write(int fd, const void *buf, size_t size)
{
OSErr err;
IOParam pb;
if (!crt_fd_tab[fd].fd) return cwrite(fd,buf,size);
else if (crt_fd_tab[fd].flags & O_PIPE)
{
return writepipe(fd, (char *)buf, size);
}
else
{
pb.ioCompletion = 0;
pb.ioRefNum = crt_fd_tab[fd].fd;
pb.ioReqCount = size;
pb.ioPosMode = fsAtMark;
pb.ioBuffer = (void *)buf;
if (crt_fd_tab[fd].flags & O_TEXT)
{
void *tmpmem = NewPtr(size);
char *newp = pb.ioBuffer = tmpmem;
char *oldbuf = (char *)buf;
while (size--)
{
if (*oldbuf == '\r')
{
*newp++ = '\n';
oldbuf++;
}
else *newp++ = *oldbuf++;
}
PBWriteSync((ParmBlkPtr)&pb);
DisposPtr(tmpmem);
}
else PBWriteSync((ParmBlkPtr)&pb);
err = pb.ioResult;
mysleep(1);
return pb.ioActCount;
}
}
#include <sys/uio.h>
int writev(int fd, const struct iovec *iov, int iovcnt)
{
int i;
for (i = 0; i < iovcnt; i++)
{
write(fd, iov[i].iov_base, iov[i].iov_len);
}
}